home *** CD-ROM | disk | FTP | other *** search
- /* Fill in the C-templates
- * Header.tpl
- * AutoDoc.tpl
- *
- * written 18/09/1993 by Lars Hanke
- * © 1993 by MGR-Software, Asgard
- * contact: mgr@asgard.bo.open.de
- *
- * Header.tpl:
- * Pass HEADER as argument, the rest is done right away
- *
- * Fills in dates, filename and the project name taken from
- * the parental drawer's name
- *
- * AutoDoc.tpl:
- * Pass IDOC for an autodoc marked internal or GDOC for a
- * standard autodoc template
- *
- * The autodoc template must be followed by a strict ANSI
- * function declaration. Function names, prototypes and
- * synopsis are guessed from that.
- * By now however any brace inside the definition won't
- * be handled following that function pointers won't produce
- * correct prototypes. Furthermore the whole declaration must
- * rest in a single line
- *
- * History:
- *
- * 07/02/94 made it accept (void *) as functions with a return
- * value. Rewrote blkrep according to the new WRITE
- * blockreplace features.
- * 13/11/93 added the static keyword
- * 17/10/93 added the rest of the declaration keywords such as
- * __asm, __saveds, __regargs, __stdargs, __a?, __d?,
- * __inline. Furthermore rewrote the line acquisition to
- * SetRexxClip to allow infinite line lengths
- * Finally made it accept type function(void) as a valid
- * definition. It should now accept anything but function
- * pointers
- * 23/09/93 introduced some expanded keywords namely signed,
- * unsigned and register. I know there are more, but
- * I lack the time complete this
- * 18/09/93 got it running the first time
- */
-
- arg tpl_type id
-
- IF ~show('P',"WRITE")
- THEN DO
- say 'This script does not make sense without the "WRITE" editor !'
- exit 10
- END
-
- address 'WRITE'
- options results
-
- 'VERSIONCHECK 31090 "Templates.wrx"'
- IF RC~=0 THEN DO
- exit 10
- END
-
- if (id="") then 'LockWindow _CurrentID'
- else 'LockWindow' id
-
- if (RC ~= 0)
- then do
- 'MessageOK "You should have a window!"'
- exit 10
- end
-
- if(tpl_type="")
- then do
- 'MessageOK "You must specify the template type!"'
- 'LockWindow 0'
- exit 10
- end
-
- /* Find bounds of the loaded template */
- 'Silent'
-
- 'GETVAR "_XPOS"'
- a.x=RESULT
- 'GETVAR "_YPOS"'
- a.y=RESULT
-
- 'SETVAR "_FindString" "*/"'
- 'Find @CURSOR @CURSOR @EOT @EOT {@SILENT}'
- 'CURSORRIGHT 1'
- 'CURSORRIGHT 1'
-
- 'GETVAR "_XPOS"'
- b.x=RESULT
- 'GETVAR "_YPOS"'
- b.y=RESULT
-
- /* Get filename and base directory as project name */
-
- 'GETVAR "_FILE"'
- file=RESULT
- 'GETVAR "_FILEPATH"'
- proj=RESULT
-
- dir=lastpos('/',proj)
- if dir = 0 then dir=lastpos(':',proj)
- if dir ~= 0 then proj=delstr(proj,1,dir)
-
- /* Get relevant dates */
-
- year=delstr(date('s'),5)
- revdate=date('E')
-
- /* Kill the internal flag, if we're doing global autodocs */
-
- if (tpl_type = "GDOC") then
- do
- 'GOTO' a.x+5 a.y
- 'DELETE'
- 'WRITECHAR' c2d('*')
- end
-
- /* Setup synopsis and prototype, if we're dealing with autodocs */
-
- if ((tpl_type = "GDOC") | (tpl_type = "IDOC")) then
- do
-
- /* get the line we expect to hold the function declaration */
-
- 'GETVAR "_WordDef"'
- w_def=RESULT
- 'SETVAR "_WordDef" "0"'
- 'GOTO' b.x b.y
- 'NEXTWORD'
- 'SetRexxClip (WRITETemplateClip) 0 _YPos'
- line=getclip('WRITETemplateClip')
- 'SETVAR "_WordDef" "'||w_def||'"'
-
- /* get the function name and type */
-
- p=splittype(line)
- if (p=0) then
- do
- 'MessageOK "No function declaration found!"'
- call done
- end
- pc = substr(line,p,1)
- if (pc ~= "(") then
- do
- 'MessageOK "This is not a function declaration!"'
- call done
- end
-
- funcnam = st.name
- retname = ""
- if (pos("void",st.type) ~= 0) then
- do
- if (pos("*",st.type) = 0) then
- do
- retname = "NONE"
- end
- end
-
- if (retname ~= "NONE") then
- do
- if (pos("int",st.type) ~= 0) then retname = "error"
- else retname = ""
- 'GETSTRING "Function' funcnam 'returns" "'||retname||'"'
- retname = RESULT
- synopsis = retname "=" st.name "("
- end
- else synopsis = st.name "("
- proto = st.type st.name "("
-
- /* now scan arguments */
-
- inputs=""
- st.help = strip(delstr(line,1,p))
- pce = substr(st.help,1,1)
- if (pce = ")") then /* check for empty chain */
- do
- synopsis = synopsis ")"
- proto = proto "void )"
- inputs = "NONE"
- end
- else
- do while ((pc = "(") | (pc = ","))
- line = delstr(line,1,p)
- p = splittype(line)
- if (p=0) then
- do
- if(words(st.help)=0 & words(st.type)=1) then
- do
- if(pos("void",st.type) ~= 0) then
- do
- proto = proto st.type
- inputs = "NONE"
- p = gpoint
- end
- else inputs = "##ERROR##"
- end
- else inputs = "##ERROR##"
- if inputs == "##ERROR##" then
- do
- 'MessageOK "Incorrect argument definition!\n'||proto'???"'
- call done
- end
- end
- pc = substr(line,p,1)
-
- if inputs ~= "NONE" then
- do
- synopsis = synopsis st.name
- proto = proto st.type
- inputs = inputs||st.name
- end
-
- if (pc ~= ")") then
- if (pc = ",") then
- do
- if inputs == "NONE" then do
- 'MessageOK "You cannot chain void stubs:' proto ',???"'
- call done
- end
- synopsis = synopsis||","
- proto = proto||","
- inputs = inputs||";"
- end
- else
- do
- 'MessageOK "Incorrect delemiter in arguments:' pc||'\n'||proto'???"'
- call done
- end
- else
- do
- synopsis = synopsis ")"
- proto = proto ")"
- end
- end
- end
-
- 'GETVAR "_CaseSense"'
- case=RESULT
- 'SETVAR "_CaseSense" "0"'
-
- call blkrep "$(Project)",proj
- call blkrep "$(File)",file
- call blkrep "$(Date)",revdate
- call blkrep "$(Year)",year
-
- /* Now the autodoc specifiy stuff */
-
- if ((tpl_type = "GDOC") | (tpl_type = "IDOC")) then
- do
- call blkrep "$(Function)",funcnam
- call blkrep "$(Synopsis)",synopsis
- call blkrep "$(Prototype)",proto
- call blkrep "$(Returns)",retname
-
- /* Finally build the input list */
-
- 'GOTO' a.x a.y
- 'SETVAR "_FindString" "$(Inputs)"'
- 'FIND @CURSOR @CURSOR @EOT @EOT {@SILENT}'
- if(RC = 0) then
- do
- 'GETVAR "_XPOS"'
- x=RESULT
- 'GETVAR "_YPOS"'
- y=RESULT
- if ((y<b.y) | ((y=b.y) & (x~>b.x))) then
- do
- 'DeleteLine'
- do until (l ~> 0)
- 'UnDelLine'
- 'Goto @SOL @SOL'
- p = pos(';',inputs)
- if (p = 0) then
- do
- line = inputs
- inputs = ""
- end
- else do
- line = left(inputs,p-1)
- inputs = delstr(inputs,1,p)
- end
- l =length(inputs)
- 'SETVAR "_ReplaceString" "'||line||'"'
- 'REPLACE @CURSOR @CURSOR @EOT @EOT {@SILENT @NOREQ}'
- 'CURSORDOWN 1'
- end
- end
- end
- end
-
- 'SETVAR "_CaseSense" "'||case||'"'
- call done
-
- /* replace all in block */
-
- blkrep: procedure EXPOSE a. b.
- parse arg old, new
-
- 'SETVAR "_FindString" "'||old||'"'
- 'SETVAR "_ReplaceString" "'||new||'"'
- 'REPLACE' a.x a.y b.x b.y '{@SILENT @NOREQ @ALL}'
-
- return
-
- /* gets constructs like:
- st.line=" struct foo * bar[] , ..."
- and produces
- st.type="struct foo **"
- st.name="bar"
- and returns the position of the comma;
- it accepts commas and parenthesa as delemiters. */
-
- splittype: procedure EXPOSE st. gpoint
- parse arg st.line
-
- st.help=st.line
- c=pos('(',st.help)
- if c=0 then c=pos(',',st.help)
- if c=0 then c=pos(')',st.help)
- if c=0 then
- do
- gpoint = 0
- return 0
- end
-
- gpoint = c
- st.help=delstr(st.help,c)
- st.help=strip(st.help)
-
- /* collect prefixes */
-
- st.run=1
- st.type = ""
- do while (st.run > 0 )
- st.item=subword(st.help,1,1)
- select
- when st.item == "struct" then st.run=1
- when st.item == "unsigned" then st.run=2
- when st.item == "register" then st.run=3
- when st.item == "signed" then st.run=4
- when st.item == "__saveds" then st.run=5
- when st.item == "__asm" then st.run=6
- when left(st.item ,3) == "__a" then do
- if length(st.item = 4) & datatype(right(st.item,1),'w') then st.run = 7
- end
- when left(st.item ,3) == "__d" then do
- if length(st.item = 4) & datatype(right(st.item,1),'w') then st.run = 8
- end
- when st.item == "__regargs" then st.run = 9
- when st.item == "__stdargs" then st.run = 10
- when st.item == "__inline" then st.run = 11
- when st.item == "const" then st.run = 12
- when st.item == "static" then st.run = 13
- otherwise st.run=0
- end
-
- /* the last entry is no keyword, but an arbitrary type that we add here in the
- same line with keywords. However only keywords will be removed from st.help */
-
- st.type = st.type st.item
- if(st.run > 0) then st.help=strip(delword(st.help,1,1))
- end
-
- /* collect pointer asterisks and arrays */
-
- st.help=strip(delword(st.help,1,1))
- a=0
- do while left(st.help,1)="*"
- a=a+1
- st.help=strip(delstr(st.help,1,1))
- end
- do while right(st.help,2)="[]"
- a=a+1
- st.help=trim(delstr(st.help,length(st.help)-1))
- end
-
- if (a ~= 0) then st.type=st.type copies("*",a)
- st.type=strip(st.type)
- if words(st.help)=1 then st.name=st.help
- else return 0
-
- return c
-
- /* exit this program */
-
- done: procedure
-
- 'Window 0 0 0 0'
- 'LockWindow 0'
- exit 0
-